/**
 * Created by zhoulin on 2019/3/31.
 */

//接口配置
var _API = {
    admin_index_doLogin:_PROXY.admin_service+"/api/index/doLogin"
};

var app = new Vue({
    el: '#app',
    data: {
    },
    //进入页面初始化方法
    created: function () {
        var that = this;

    },
    methods: {
        doLogin:function () {
            var that = this;

            if(empty(that.$refs.uname.value)){
                that.$refs.uname.focus();
                layer.msg("<span style='color:red'>用户名不能为空！</span>", {time: 1500, icon:5});
                return ;
            }
            if(empty(that.$refs.pword.value)){
                that.$refs.pword.focus();
                layer.msg("<span style='color:red'>密码不能为空！</span>", {time: 1500, icon:5});
                return ;
            }

            var param = {
                username:trimAll(that.$refs.uname.value),
                password:trimAll(that.$refs.pword.value)
            };

            Post(that,_HOST+_API.admin_index_doLogin,param,true)
                .then(function (response) {
                    // 响应成功回调
                    console.log(response)
                    if(response){
                        if(response.success){
                            layer.msg("<span style='color: #000'>"+response.msg+"</span>", {time: 1500, icon:1});
                            sessionStorageUtils.setJsonStr(storageKey.sessionStorageKey.token,response.token);
                            sessionStorageUtils.setJsonStr(storageKey.sessionStorageKey.permCodes,response.permCodes);
                            setTimeout(function () {
                                window.location.href = "html/index.html";
                            },1500)
                        }else {
                            layer.msg("<span style='color: red'>"+response.msg+"</span>", {time: 1500, icon:5});
                        }
                    }
                })
        },
    }

})